package com.hisen.algorithm.sort;

public class BubbleSort {

    /**
     * 对数组进行正序排列
     *
     * @param numArr 需要排序的数组
     * @return 排序之后的数组
     */
    public static int[] sort(int[] numArr) {
        if (numArr == null || numArr.length <= 1) {
            return numArr;
        }
        int length = numArr.length;
        for (int i = 0; i < length - 1; i++) {
            for (int j = 0; j < length - i - 1; j++) {
                if (numArr[j] > numArr[j + 1]) {
                    int m = numArr[j + 1];
                    numArr[j + 1] = numArr[j];
                    numArr[j] = m;
                }
            }
        }
        return numArr;
    }
}
